#include "3dd_lua.h"

//==============================================================================
// Configuration Script variables
//==============================================================================
// Spline color
G3::COL3F G3CS_Fg_Color (1.0f, 1.0f, 1.0f);
// Spline smoothness (default is 10)
int G3CS_Subdivisions = 10;
bool G3CS_Display_Grid = false;
bool G3CS_DisplayAxis = true;
G3::COL3F G3CS_Bg_Color (0.0f, 0.0f, 0.0f);
G3::VEC2I G3CS_Resolution (800, 600);
int G3CS_ColDepth = 24;
bool G3CS_FullScreen = false;
float G3CS_SplineWidth = 0.01f;
float G3CS_SplineDetail = 4.0f;
float G3CS_3DM_PlanarSensitivity = 10.0f;
float G3CS_3DM_RotateSensitivity = 1 / 10000.0f;
float G3CS_WII_NunchukRotateSensitivity = 100000.0f;
float G3CS_WII_NunchukNoiseLevel = 0.02f;
float G3CS_3DM_DepthSensitivity = 1 / 3.0f;
bool G3CS_3DM_UseNormalMouse = false;
int G3CS_WII_IRSensitivity = 3;
float G3CS_WII_DepthNoiseReduction = 0.1f;
int G3CS_WII_NoiseFilterIterations = 10;
float G3CS_WII_MinDepth = 300.0f;
float G3CS_WII_DepthSensitivity = 4.0f;
float G3CS_WII_ZoomSensitivity = 3.0f;
G3::VEC3F G3CS_Lightpos;
G3::VEC3F G3CS_Camerapos;
bool G3CS_Profiling = false;

//==============================================================================
// Loads a Lua configuration script from a filestream
//==============================================================================
bool LoadConfig (G3::STREAM *aStream) {
	bool Result = false;

    if (!aStream) {
        G3::MainLog.Report ("LoadConfig: Stream argument is a NULL pointer\n");
        return false;
    }

	tolua_3ddcs_open (G3::MainLuaHandler.LuaState);

	if (G3::MainLuaHandler.Execute (aStream) == -1) {
		G3::MainLog.Report ("LoadConfig: Failed to execute the script\n");
		return false;
	}

	G3::MainLog.Report ("The configuration script was executed successfully\n");

	return Result;
}

//==============================================================================
// Loads a Lua configuration script from a file
//==============================================================================
bool LoadConfig (const char *aFilename) {
    G3::MainLog.Report ("Loading configuration from \"%s\"..\n", aFilename);

    if (!aFilename) {
        G3::MainLog.Report ("LoadConfig: Filename argument is a NULL pointer\n");
        return false;
    }

	string Path = G3::MainFilesys.GetPath (aFilename);

    if (!LoadConfig (G3::MainFileHandler.ReadWholeFile (Path.c_str ()))) {
        G3::MainLog.Report ("Failed to load the configuration script..\n");
        return false;
    }

    G3::MainLog.Report ("The configuration script has been successfully loaded..\n");
	return true;
}

